//
//  SPGameViewModel.h
//  ShandongPoker
//
//  Created by Developer on 2025-01-08.
//  Copyright © 2025 ShandongPoker. All rights reserved.
//

#import "../../Core/Base/BaseViewModel.h"
#import "../../Core/Utils/SPConstants.h"

@class SPPlayer;
@class SPCard;

NS_ASSUME_NONNULL_BEGIN

/**
 * 游戏主界面ViewModel
 * 管理游戏状态和数据绑定
 */
@interface SPGameViewModel : BaseViewModel

#pragma mark - 游戏状态

/// 当前游戏状态
@property (nonatomic, assign, readonly) SPGameState gameState;

/// 当前底池金额
@property (nonatomic, assign, readonly) NSInteger currentPot;

/// 当前轮次（第几轮下注）
@property (nonatomic, assign, readonly) NSInteger currentRound;

/// 是否游戏暂停
@property (nonatomic, assign, readonly) BOOL isPaused;

#pragma mark - 玩家数据

/// 所有玩家列表
@property (nonatomic, strong, readonly) NSArray<SPPlayer *> *players;

/// 当前玩家（人类玩家）
@property (nonatomic, strong, readonly, nullable) SPPlayer *currentPlayer;

/// 当前行动玩家
@property (nonatomic, strong, readonly, nullable) SPPlayer *activePlayer;

#pragma mark - 牌面数据

/// 公共牌
@property (nonatomic, strong, readonly) NSArray<SPCard *> *communityCards;

/// 当前玩家手牌
@property (nonatomic, strong, readonly) NSArray<SPCard *> *playerHoleCards;

#pragma mark - 数据绑定回调

/// 游戏状态变化回调
@property (nonatomic, copy, nullable) void(^gameStateDidChange)(SPGameState newState);

/// 底池金额变化回调
@property (nonatomic, copy, nullable) void(^potDidChange)(NSInteger newPot);

/// 公共牌更新回调
@property (nonatomic, copy, nullable) void(^communityCardsDidUpdate)(NSArray<SPCard *> *cards);

/// 玩家手牌更新回调
@property (nonatomic, copy, nullable) void(^playerCardsDidUpdate)(NSArray<SPCard *> *cards);

/// 玩家行动回调
@property (nonatomic, copy, nullable) void(^playerDidAct)(SPPlayer *player, SPPlayerAction action, NSInteger amount);

/// 游戏结束回调
@property (nonatomic, copy, nullable) void(^gameDidEnd)(SPPlayer * _Nullable winner, NSInteger winAmount);

#pragma mark - 游戏控制方法

/**
 * 开始新游戏
 * @param playerNames 玩家名称数组
 * @param aiDifficulty AI难度
 */
- (void)startNewGameWithPlayers:(NSArray<NSString *> *)playerNames 
                   aiDifficulty:(SPAIDifficulty)aiDifficulty;

/**
 * 暂停游戏
 */
- (void)pauseGame;

/**
 * 恢复游戏
 */
- (void)resumeGame;

/**
 * 结束游戏
 */
- (void)endGame;

#pragma mark - 玩家操作方法

/**
 * 玩家弃牌
 */
- (void)playerFold;

/**
 * 玩家过牌
 */
- (void)playerCheck;

/**
 * 玩家跟注
 */
- (void)playerCall;

/**
 * 玩家加注
 * @param amount 加注金额
 */
- (void)playerRaise:(NSInteger)amount;

/**
 * 玩家全下
 */
- (void)playerAllIn;

#pragma mark - 查询方法

/**
 * 获取当前需要跟注的金额
 * @return 跟注金额
 */
- (NSInteger)getCurrentCallAmount;

/**
 * 获取最小加注金额
 * @return 最小加注金额
 */
- (NSInteger)getMinRaiseAmount;

/**
 * 获取最大加注金额
 * @return 最大加注金额
 */
- (NSInteger)getMaxRaiseAmount;

/**
 * 检查玩家是否可以执行指定操作
 * @param action 玩家操作
 * @return 是否可以执行
 */
- (BOOL)canPlayerPerformAction:(SPPlayerAction)action;

@end

NS_ASSUME_NONNULL_END